/*
 * File:   CSStringTest.c
 * Author: Muhammad Anis
 *
 * Created on Sep 25, 2012, 12:10:14 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include "CUnit/Basic.h"
#include "CSString.h"

/*
 * CUnit Test Suite
 */

int init_suite(void) {
    return 0;
}

int clean_suite(void) {
    return 0;
}

void test1() {
    char* input = "halokk";    
    CU_ASSERT(GetCSStringLength(input) == 6);
}

void testGetCharAt() {
    CSString string = "haloks";
    CU_ASSERT(GetCharAt(string,5)=='s');
}

void testCopyString(){
    CSString string1 = "saya string 1";
    char string2[100];    
    CopyString(string1,string2,0,4);
    CU_ASSERT(EqCSString(string2,"saya"));    
}

void testTrim(){
    CSString string1 = "  saya  ";
    CU_ASSERT(EqCSString(Trim(string1),"saya"));
}
int main() {
    CU_pSuite pSuite = NULL;

    /* Initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* Add a suite to the registry */
    pSuite = CU_add_suite("CSStringTest", init_suite, clean_suite);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Add the tests to the suite */
    if ((NULL == CU_add_test(pSuite, "test1", test1)) ||
            (NULL == CU_add_test(pSuite, "test2", testGetCharAt)) ||
            (NULL == CU_add_test(pSuite, "test4", testTrim))
            ) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Run all tests using the CUnit Basic interface */
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    CU_cleanup_registry();
    return CU_get_error();
}
